package com.fivetiger.service.impl;
import com.fivetiger.dao.PetsMaintenanceDao;
import com.fivetiger.dto.PetsFlag;
import com.fivetiger.entity.PetsMaintenance;
import com.fivetiger.service.inte.PetsMaintenanceService;
import com.fivetiger.util.RUtil;
import com.fivetiger.vo.PageBean;
import com.fivetiger.vo.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class PetsMaintenanceServiceImpl implements PetsMaintenanceService {
    @Autowired
    private PetsMaintenanceDao dao;

    @Override
    public R insert(PetsMaintenance pets) {
        if(pets != null){
            if(dao.insert(pets)>0){
                System.err.println(RUtil.ok());
                return RUtil.ok();
            }
        }
        return RUtil.fail();
    }

    @Override
    public PageBean selectPage(int page, int limit) {
        PageHelper.startPage(page,limit);
        PageInfo<PetsMaintenance> pageInfo = new PageInfo<>(dao.selectAll());
        PageBean pageBean = new PageBean(0, "", pageInfo.getTotal(), pageInfo.getList());
        return pageBean;
    }

    @Override
    public PageBean selectPageByName(int page, int limit) {
        PageHelper.startPage(page,limit);
        PageInfo<PetsMaintenance> pageInfo = new PageInfo<>(dao.selectAll());
        PageBean pageBean = new PageBean(0, "", pageInfo.getTotal(), pageInfo.getList());
        return pageBean;
    }

    @Override
    public R change(PetsMaintenance petsMaintenance) {
        if (dao.update(petsMaintenance)>0){
            return RUtil.ok();
        }else {
            return RUtil.fail();
        }


    }

    @Override
    public R changeByName(PetsFlag petsFlag) {
        if (dao.updateByName(petsFlag)>0){
            return RUtil.ok();
        }else {
            return RUtil.fail();
        }
    }

    @Override
    public R delete(PetsMaintenance petsMaintenance) {
        if(dao.delete(petsMaintenance)>0){
            return RUtil.ok();
        }else {
            return RUtil.fail();
        }
    }
}
